package com.zbkj.service.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zbkj.common.model.doctor.Doctor;
import com.zbkj.common.model.order.StoreOrder;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.DoctorSearchRequest;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.StoreOrderSearchRequest;
import com.zbkj.common.response.DoctorResponse;
import com.zbkj.common.response.StoreOrderDetailResponse;
import com.zbkj.service.dao.ArticleDao;
import com.zbkj.service.dao.DoctorDao;
import com.zbkj.service.service.DoctorService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: zhaoyongke
 * @create: 2025-02-21 10:08
 * @description: 医生
 */


@Service
public class DoctorServiceImpl implements DoctorService {

    private static final Logger logger = LoggerFactory.getLogger(DoctorServiceImpl.class);

    @Resource
    private DoctorDao dao;


    @Override
    public List<Doctor> getAdminList(DoctorSearchRequest request, PageParamRequest pageParamRequest) {
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "name", "image", "zw", "info", "sc_info", "jj_info", "sc_label", "price"
                , "score", "num", "is_sj", "ks", "create_time"
                , "status", "remark", "update_time");
        if (StrUtil.isNotBlank(request.getKs())) {
            queryWrapper.eq("ks", request.getKs());
        }
        if (StrUtil.isNotBlank(request.getName())) {
            queryWrapper.like("name", request.getName());
        }
        queryWrapper.orderByDesc("id");
        List<Doctor> orderList = dao.selectList(queryWrapper);
        return  orderList;

    }

    @Override
    public List<Doctor> getAllAdminList() {
        QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "name", "image", "zw", "info", "sc_info", "jj_info", "sc_label", "price"
                , "score", "num", "is_sj", "ks", "create_time"
                , "status", "remark", "update_time");
        queryWrapper.orderByDesc("id");
        List<Doctor> orderList = dao.selectList(queryWrapper);
        return  orderList;

    }

    /**
     * 查询医生信息
     *
     * @param id 医生信息主键
     * @return 医生信息
     */
    @Override
    public Doctor selectEbDoctorById(String id)
    {
        return dao.selectById(id);
    }


    /**
     * 新增医生信息
     *
     * @param ebDoctor 医生信息
     * @return 结果
     */
    @Override
    public int insertEbDoctor(Doctor ebDoctor)
    {
        ebDoctor.setCreateTime(DateUtil.date());
        return dao.insert(ebDoctor);
    }

    /**
     * 修改医生信息
     *
     * @param ebDoctor 医生信息
     * @return 结果
     */
    @Override
    public int updateEbDoctor(Doctor ebDoctor)
    {
        ebDoctor.setUpdateTime(DateUtil.date());
        return dao.updateById(ebDoctor);
    }

    /**
     * 批量删除医生信息
     *
     * @param ids 需要删除的医生信息主键
     * @return 结果
     */
    @Override
    public int deleteEbDoctorByIds(String[] ids)
    {

        return dao.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除医生信息信息
     *
     * @param id 医生信息主键
     * @return 结果
     */
    @Override
    public int deleteEbDoctorById(String id)
    {
        return dao.deleteById(id);
    }

}
